<template>
	<view class="box">
		<u-navbar :is-back="true" title="登录"></u-navbar>
		<view class="container">
			<view class="logo">
				<u-image width="166rpx" height="116rpx" :src="logo"></u-image>
			</view>
			<view class="title cxc">
				账户登录
			</view>
			<u-form :model="form" ref="form1" :error-type="errorType">
				<u-form-item prop="phone">
					<view class="ipt flc">
						<view class="icon">
							<u-icon :name="'/static/icons/lock.png'" size="26"></u-icon>
						</view>
						<u-input class="ml2" v-model="form.phone" placeholder="请输入注册手机号" />
					</view>
				</u-form-item>

				<u-form-item prop="password">
					<view class="ipt flc">
						<view class="icon">
							<u-icon :name="'/static/icons/lock.png'" size="26"></u-icon>
						</view>
						<u-input class="ml2 password" type="password" v-model="form.password" placeholder="请输入密码" />
					</view>
				</u-form-item>
			</u-form>
			<view class="forgetPassword ptc" @click="forget">
				忘记密码?
			</view>
			<view class="btn" @click="submit">
				立即登录
			</view>
			<view class="tips " @click="register">
				<view class="tip flc">
					<span class="r ptc">还没有账号，</span>
					<span class="l cxc">立即注册</span>
				</view>
			</view>
		</view>

	</view>

</template>

<script>
	import {
		getLogo
	} from '../../api/index';
	import { login } from '../../api/login';
	import { toastC,toast } from '../../utils/common';
	export default {
		data() {
			return {
				form: {
					phone: '',
					password: ""
				},
				rules: {
					phone: [{
						required: true,
						message: '请输入手机号',
						trigger: ['change', 'blur']
					}],
					password: [{
						required: true,
						message: '请输入密码',
						trigger: ['change', 'blur']
					}]

				},
				logo: "",
				errorType:['toast']
			};
		},
		onReady() {
			this.$refs.form1.setRules(this.rules);
		},
		onLoad() {
			getLogo().then(res => {
				this.logo = res.data.logo
			})
		},
		methods: {
			onSelect1(arr) {
				let current = arr[0];
				let value = current.value;
				this.select1.current = current;
				this.form.sex = value;
			},
			submit() {
				this.$refs.form1.validate((valid) => {
					console.log(valid);
					if (valid) {
						login({
							phone:this.form.phone,
							password:this.form.password
						}).then(res=>{
							if(res.code==200){
								uni.setStorageSync("access_token", res.data.access_token);
								uni.setStorageSync("token_type", res.data.token_type);
								toastC("登录成功")
								setTimeout(()=>{
									uni.navigateBack()
								},300)
							}else{
								toast(res.message)
							}
							
						})
						
					}
				})
			},
			onCalendar1(e) {
				this.form.birthday = e.result;
			},
			forget() {
				uni.navigateTo({
					url: '/page/forgetPassword/forgetPassword'
				})
			},
			register() {
				uni.navigateTo({
					url: '/page/register/register'
				})
			}
		}
	};
</script>

<style lang="scss" scoped>
	.container {
		margin-top: 20rpx;
		background-color: #fff;
		width: 750rpx;
		height: calc(100vh - 96rpx);
		box-sizing: border-box;
		padding: 20rpx;
	}

	.logo {
		width: 200rpx;
		height: 200rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 10rpx 20rpx 0rpx rgba(51, 51, 51, 0.1);
		border-radius: 30rpx;
		margin: 40rpx auto;
		box-sizing: border-box;
		padding: 42rpx 17rpx;
	}

	.title {
		height: 40rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		font-size: 42rpx;
		margin: 40rpx 0;
	}

	.forgetPassword {
		text-align: right;
		font-size: 28rpx;
		margin: 20rpx 0;
	}

	.btn {
		width: 650rpx;
		height: 80rpx;
		background: linear-gradient(90deg, #FD4120, #F47749);
		border-radius: 40rpx;
		margin: 40rpx auto;
		text-align: center;
		line-height: 80rpx;
		font-size: 30rpx;
		color: #FFFFFF;

	}

	.tips {
		font-size: 28rpx;
		text-align: center;
		width: 710rpx;
		display: flex;
		justify-content: center;
	}
</style>